package com.tczs.dispatch.response;

import com.tczs.web.config.CustomerResponseHtml;
import com.tczs.server.response.Response;
import io.netty.handler.codec.http.FullHttpResponse;
import io.netty.handler.codec.http.HttpResponseStatus;
import org.apache.log4j.Logger;

/**
 * 应用接口返回的数据匹配对应的服务器返回的数据
 */
public class MappingResponse {
    private static Logger logger = Logger.getLogger(MappingResponse.class);

    public static FullHttpResponse mappingHttpResponse(ResponseResult result){
        logger.info(result.toString());
        if(result.getCode() == 200){
            if(result.getType() == ResponseType.FILE)
                return Response.okFileResponse(result.getFilePath());
            else if(result.getType() == ResponseType.JSON)
                return Response.okResponse(result.getValue().toJSONString());
            else
                return Response.getStreamResponse(result.getFilePath());
        }else if(result.getCode() == 404){
            return Response.notFoundResponse();
        }else if(result.getCode() == 555){
            return Response.okResponse(result.getValue().toJSONString());
//            return Response.getResponse(CustomerResponseHtml.getHtmlData(result.getErrorMessage()),
//                    HttpResponseStatus.INTERNAL_SERVER_ERROR,Response.HTML);
        } else{
            return Response.errorResponse();
        }
    }
}
